package com.richman.view;

import java.awt.BorderLayout;
import java.awt.Container;
import java.awt.Dimension;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStreamReader;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Vector;

import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.JTabbedPane;
import javax.swing.JPanel;
import javax.swing.JButton;
import javax.swing.JTextArea;

import com.richman.controller.DaShui;
import com.richman.ps38.entity.Event;
import com.richman.ps38.entity.HGEvent;
import com.richman.ps38.entity.ISNPS38Event;
import com.richman.ps38.entity.ISNEvent;
import com.richman.ps38.entity.ISNTeam;
import com.richman.utils.Common;

import java.awt.FlowLayout;
import javax.swing.BoxLayout;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.awt.event.ActionEvent;



public class MainWindow extends JFrame {

	/**
	 * 
	 */
	private static final long serialVersionUID = -285041842903797245L;
	
	public MainWindow(){
        intiComponent();  
        setTitle("负水主机");
        
        
        setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
        
        
        
        addWindowListener(new WindowAdapter() {
    		public void windowClosing(WindowEvent e) {
    			int n = JOptionPane.showConfirmDialog(null, "确认退出吗?", "退出程序",
    					JOptionPane.YES_NO_OPTION);
    			if (n == JOptionPane.YES_OPTION) {					
    				System.exit(0);
    			}else{
    				
    				setVisible(true);
    			}

    		}
    	});
        
        
	}
	
	
	
	
	

	private JTabbedPane jTabbedpane = new JTabbedPane();// ���ѡ������  


	EventWindowPane eventPane = new EventWindowPane();
	
	AccountWindowPane accountWndPane = new AccountWindowPane();
	
	
	TeamMatchWindowPane teamMatchWindowPane = new TeamMatchWindowPane();
	
	
	
	SettingPane settingPane = new SettingPane();
	
	private JPanel panel = new JPanel();

	JTextArea hgTextArea = null;
	
	JTextArea PS38TextArea = null;
	
	//ps38
	
	public Vector<String[]> getPS38Accounts(){
		return accountWndPane.getPS38Accounts();
	}
	
	
	
	public Vector<String[]> getPS38DanshiAccounts(){
		return accountWndPane.getPS38DanshiAccounts();
	}
	
	//ps38
	
	
	//hg
	
	public Vector<String[]> getHGAccounts() {
		return accountWndPane.getHGAccounts();
	}
	
	//isn
	public Vector<String[]> getISNAccounts(){
		return accountWndPane.getISNAccounts();
	}
	
	//hg
	
	

    private void intiComponent()  
    {  

		final Container container = getContentPane();
		
		container.setLayout(new BorderLayout());
		

		container.add(panel,BorderLayout.NORTH);
		
		
		
		container.add(jTabbedpane, BorderLayout.CENTER);  
		
		panel.setPreferredSize(new Dimension(0, 150));
		
		jTabbedpane.add(eventPane,"赛事");
		
		jTabbedpane.add(accountWndPane,"帐号");
		
		
		jTabbedpane.add(teamMatchWindowPane, "合并球队");
		
		jTabbedpane.add(settingPane,"设置");
		
		getContentPane().add(panel, BorderLayout.NORTH);
		panel.setLayout(null);
		
		JButton stopButton = new JButton("停止");
		stopButton.setEnabled(false);
		
		
		JButton startButton = new JButton("启动");
		startButton.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				
				//DaShui.bStartEngine = true;
				DaShui.StartEngine();
				if(DaShui.bStartEngine == true) {
					startButton.setEnabled(false);
					stopButton.setEnabled(true);
					
				}
				
			}
		});
		startButton.setBounds(10, 64, 86, 23);
		panel.add(startButton);
		

		stopButton.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				
				DaShui.bStartEngine = false;
				startButton.setEnabled(true);
				stopButton.setEnabled(false);
				
			}
		});
		stopButton.setBounds(126, 64, 86, 23);
		panel.add(stopButton);
		
		hgTextArea = new JTextArea();
		hgTextArea.setBounds(240, 0, 767, 57);
		hgTextArea.setEditable(false);
		
		panel.add(hgTextArea);
		
		PS38TextArea = new JTextArea();
		PS38TextArea.setBounds(240, 77, 767, 63);
		panel.add(PS38TextArea);
		PS38TextArea.setEditable(false);
		

        setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE);  

        setBounds(100, 100, 1660, 900); 

    }
    
    
    
    public void updateHGTextArea(String text) {
    	hgTextArea.setText(text);
    }
    
	public void updatePS38TextArea(String text) {
		
		PS38TextArea.setText(text);
	}
    

	public void updatePS38EventsTable(Vector<Event> events) {
		
		eventPane.updatePS38EventsTable(events);
	}  
	
	
	public void updateISNEventsTable(Vector<ISNEvent> events) {
		
		eventPane.updateISNEventsTable(events);
	}  
	
	
	public void updateHGEventsTable(Vector<HGEvent> events) {
		
		eventPane.updateHGEventsTable(events);
	}  
	
	
	public void updateHGPS38EventsTable(Vector<ISNPS38Event> events) {
		
		eventPane.updateHGPS38EventsTable(events);
	}  
	
	
	
	public void updateTeamMatchHGTeams(Vector<HGEvent> hgevents) {
		teamMatchWindowPane.updateTeamMatchHGTeams(hgevents);
	}
	
	public void updateTeamMatchISNTeams(Vector<ISNTeam> isnevents) {
		teamMatchWindowPane.updateTeamMatchisnTeams(isnevents);
	}
	
	
	public void updateTeamMatchPS38Teams(Vector<Event> ps38events) {
		teamMatchWindowPane.updateTeamMatchPS38Teams(ps38events);
	}
	
	
	
	public Vector<String[]> getISNPS38TeamsList(){
		return teamMatchWindowPane.getISNPS38TeamsList();
	}
	
	public Vector<String[]> getISNPS38LeaguesList(){
		return teamMatchWindowPane.getISNPS38LeaguesList();
	}
	
	public Vector<String[]> getHGPS38TeamsList(){
		return teamMatchWindowPane.getHGPS38TeamsList();
	}
	
	public Vector<String[]> getHGPS38LeaguesList(){
		return teamMatchWindowPane.getHGPS38LeaguesList();
	}
	
	
	public Vector<String[]> getHGISNTeamsList(){
		return teamMatchWindowPane.getHGISNTeamsList();
	}
	
	public void updateHGAccountStatus(String account, int statusCode) {
		accountWndPane.updateHGAccountStatus(account, statusCode);
	}

	public void updatePS38AccountStatus(String account, int statusCode) {
		accountWndPane.updatePS38AccountStatus(account, statusCode);
		
	}
	
	public void updateISNAccountStatus(String account, int statusCode) {
		accountWndPane.updateISNAccountStatus(account, statusCode);
	}
	
	public int getUpdateSeconds() {
		
		return settingPane.getUpdateSeconds();
	}
	
	
	
	public double getsideMinodd() {
		return settingPane.getsideMin();
	}
	
	public double getsumMinodd() {
		return settingPane.getsumMin();
	}
	
	public double getsideMaxodd() {
		return settingPane.getsideMax();
	}
	
	
	public double getsumMaxodd() {
		return settingPane.getsumMax();
	}
	
	public int getDanshiMinTime() {
		return settingPane.getDanshiMinTime();
	}


	


	public int getDanshiMaxTime() {
		return settingPane.getDanshiMaxTime();
	}




	public int getGqHalfMinTime() {
		return settingPane.getGqHalfMinTime();
	}




	public int getGqHalfMaxTime() {
		return settingPane.getGqHalfMaxTime();
	}




	public int getGqWholeMinTime() {
		return settingPane.getGqWholeMinTime();
	}




	public int getGqWholeMaxTime() {
		return settingPane.getGqWholeMaxTime();
	}
	
	
	
	public void generateForbidLeagueItem() {
		settingPane.generateForbidLeagueItem();
	}
	
	public Vector<String> getForbidLeagues(){
		return settingPane.getForbidLeagues();
	}
	
	public Vector<String> getNegLeagues(){
		return settingPane.getNegLeagues();
	}
	
}

